package service.impl.v2;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dao.v2.AddressVOMapper;
import dao.v2.ConfigVOMapper;
import dao.v2.DicVOMapper;
import dao.v2.GoodVOMapper;
import dao.v2.MemberCartVOMapper;
import dao.v2.MemberLevelItemVOMapper;
import dao.v2.MemberVOMapper;
import dao.v2.OrderVOMapper;
import dao.v2.PromotionVOMapper;
import model.AddressVO;
import model.EnterpriseVO;
import model.GoodDeliveryInterCountryVO;
import model.GoodStandardVO;
import model.GoodVO;
import model.MemberCartVO;
import model.MemberVO;
import model.OrderGoodVO;
import model.OrderTimer;
import model.OrderVO;
import model.PromotionGoodVO;
import model.PromotionItemVO;
import model.PromotionVO;
import model.SendTempItemVO;
import service.v2.GoodService;
import service.v2.GoodTempService;
import service.v2.MemberCartServise;
import service.v2.TimerService;
import util.NumberUtil;
import util.PropertieUtil;
@Service
public class MemberCartServiseImpl  implements MemberCartServise {
	@Autowired
	private MemberCartVOMapper dao;
	@Autowired
	private AddressVOMapper addressVOMapper;
	
	@Autowired
	private OrderVOMapper orderVOMapper;
	
	@Autowired
	private GoodTempService goodTempService;
	
	@Autowired
	private ConfigVOMapper ConfigDao;
	
	@Autowired
	private PromotionVOMapper  promotiondao;
	
	@Autowired
	private TimerService timerService;
	@Autowired
	private MemberLevelItemVOMapper memberLevelItemDao;
	@Autowired
	private MemberVOMapper memberDao;
	@Autowired
	private DicVOMapper dicDao;
	@Autowired
	private GoodService goodService;
	@Autowired
	private GoodVOMapper goodVOMapper;
	@Autowired
	private AddressVOMapper addressDao;

	public int checkMaxNum(String standard_id, String member_id, String num) {
		return dao.checkMaxNum(standard_id, member_id, num) ;
	}
	public int upDateMemberCartVo(MemberCartVO memberCartVO) {
		return  dao.upDateMemberCartVo(memberCartVO);
	}
	public MemberCartVO selectGoodInformationtBuyOne(String standard_id, String num) {
		MemberCartVO goodInformation=dao.selectGoodInformationtBuyOne(standard_id,num);
		goodInformation.setNum(num);
		return goodInformation;
	}
	public int deleteMemberCarById(String[] arrId, String id) {
		return dao.deleteMemberCarById(arrId,id);
	}

	public List<MemberCartVO> selectmemberCartList(String id, String[] arrCartId) {
		List<MemberCartVO> memberCartList=dao.selectGoodsList(id,arrCartId);
		return memberCartList;
	}

	public List<Object> selectGoodsCouponsInfoList(String[] arrId, String member_id, MemberCartVO memberCartVO) {
		//求使用的总换券
		String use_coupons=dao.getUseCoupons(arrId);
		//求立减的额度
		String decrease_price=dao.getDecreasePrice(arrId);
		//求总换券余额
		String coupons_balance = dao.getPaidProfit(member_id);
		
		memberCartVO.setUse_coupons(use_coupons);
		memberCartVO.setDecrease_price(decrease_price);
		memberCartVO.setCoupons_balance(coupons_balance);
		memberCartVO.setCart_id(null);
		memberCartVO.setGood_standard_id(null);
		
		//求商品单价
		List<MemberCartVO> good_sellPrice=dao.getGoodSellPrice(arrId);
		
		List<Object>  list = new ArrayList<Object>();
		list.add(memberCartVO);
		list.add(good_sellPrice);
		
		return list;
	}

	public int getCartNum(String member_id) {
		return dao.getCartNum(member_id) ;
	}

	public void addCart(String id,String member_id,String num,String lang) {
		dao.addCart(id,member_id,num,lang);
	}

	public List<MemberCartVO> packageCartParam(String cart_ids) {
		List<MemberCartVO> list = dao.getCartStandarsIdAndNuns(cart_ids);
		return list;
	}

	public List<MemberCartVO> selectmemberCartListBuy(String cart_ids,String member_id) {
		return dao.selectmemberCartListBuy(cart_ids,member_id);
	}

	public AddressVO getMemberAddressById(String address_id) {
		// TODO Auto-generated method stub
		return addressVOMapper.getAddressById(address_id);
	}

	public MemberVO getMemberById(String member_id) {
		// TODO Auto-generated method stub
		return dao.getMemberById(member_id);
	}

	public int checkMemberCartId(String member_id, String cart_id) {
		return dao.checkMemberCartId(member_id,cart_id);
	}

	public int updateMemberCartCheck(String cart_id, String check, String member_id) {
		return dao.updateMemberCartCheck(cart_id,check,member_id);
	}

	public String checkCartExsit(String standard_id, String member_id) {
		return dao.checkCartExsit( standard_id,  member_id) ;
	}

	public void addCartNum(String id, String num) {
		dao.addCartNum( id,  num);
	}

	public List<MemberCartVO> getMemberCardById(String[] cart_id) {
		return dao.getMemberCardById(cart_id);
	}
	
	public List<MemberCartVO> selectmemberCartListBuyOne(String standard_id, String num) {
		return dao.selectmemberCartListBuyOne( standard_id,  num);
	}

	public boolean checkBuyGoosNumBySthandardTab(String cart_ids) {
		boolean bl= true;
		List<MemberCartVO> list =dao.checkBuyGoosNumBySthandardTab(cart_ids);
		
		for(int i=0;i<list.size();i++){
			if(Integer.parseInt(list.get(i).getNum()) > Integer.parseInt(list.get(i).getMaximum_n())){
				bl = false;
				break;
			}
		}
		return bl;
	}

	

	public boolean checkMemberCart(String member_id, String cart_id) {
		int count = dao.checkMemberCart(member_id,cart_id);
		if(count>0){
			return true;
		}else{
			return false;
		}
	}

	public int getSumTicket(String id, String num) {
		return dao.getSumTicket(id,num);
	}

	public String checkGoodsBuyType(List<MemberCartVO> memberCartList) {
		int n=0;
		for(int i=0; i<memberCartList.size(); i++){
			for(int j=0; j<memberCartList.get(i).getGood_list().size(); j++){
				if(!"61".equals(memberCartList.get(i).getGood_list().get(j).getBuy_type())){
					n=n+1;
				}
			}
		}
		if(n==0){
			return "Y";
		}
		return "N";
	}

	public List<MemberCartVO> packageCartAllMoneyGoodsParam(List<MemberCartVO> l) {
		List<MemberCartVO> allMoneyGoods = new ArrayList<MemberCartVO>(); 
		
		for(int i=0; i<l.size();i++){
			if("61".equals(l.get(i).getBuy_type())){
				allMoneyGoods.add(l.get(i));
			}
		}
		
		return allMoneyGoods;
	}

	public List<MemberCartVO> packageCartNotAllMoneyGoodsParam(List<MemberCartVO> l) {
		List<MemberCartVO> notAllMoneyGoods = new ArrayList<MemberCartVO>(); 
		for(int i=0; i<l.size();i++){
			if(!"61".equals(l.get(i).getBuy_type())){
				notAllMoneyGoods.add(l.get(i));
			}
		}
		return notAllMoneyGoods;
	}

	public void InsertOrder(OrderVO order) {
		// TODO Auto-generated method stub
		dao.InsertOrder(order);
	}

	public void addOrderTimer(OrderTimer orderTime) {
		// TODO Auto-generated method stub
		dao.addOrderTimer(orderTime);
	}

	public List<GoodStandardVO> getGoodStandardListById(String[] standard_Id_list) {
		// TODO Auto-generated method stub
		return dao.getGoodStandardListById(standard_Id_list);
	}

	public void addOrderGood(OrderGoodVO ordergood) {
		// TODO Auto-generated method stub
		dao.addOrderGood(ordergood);
	}

	@Override
	public List<MemberCartVO> selectNewMemberCartList(String member_id, String city_id3,String lang,String country_id) {
		List<MemberCartVO> list = dao.selectCartList(member_id,lang);
		MemberVO vo=memberDao.getSimpleInfoById(member_id);
		ArrayList<MemberCartVO> upList1 = new ArrayList<MemberCartVO>();
		ArrayList<MemberCartVO> upList2 = new ArrayList<MemberCartVO>();
		
		int n=0;
			for(int i=0;i<list.size();i++){
				List<PromotionVO> promotion_list=promotiondao.selectPromotionList(list.get(i).getGood_id());
				//判断促销商品
				if(promotion_list.size()==0){
					list.get(i).setPromotion_show("0");
				}else{
					for(int j=0;j<promotion_list.size();j++){
						int n_time = Integer.parseInt(promotion_list.get(j).getN_time());
						int s_time = Integer.parseInt(promotion_list.get(j).getS_time());
						int e_time = Integer.parseInt(promotion_list.get(j).getE_time());
						
						String showYn="";
						boolean flag = false;
						try {
							flag =goodService.promotionShow(vo, promotion_list.get(j).getMax_level());
						} catch (Exception e) {
							e.printStackTrace();
						}
						if(flag){
							showYn="1";
						}else{
							showYn="0";
						}
						if("N".equals(promotion_list.get(j).getDelete_yn())
								&&"1".equals(showYn)
								&&s_time<n_time
								&&n_time<e_time){
							list.get(i).setPromotion_show("1");
						}else{
							list.get(i).setPromotion_show("0");
						}
					}
				}
				//判断供货商id是否有变化
				if(!"".equals(list.get(i).getNew_companyId())&&!list.get(i).getCompany_id().equals(list.get(i).getNew_companyId())){
					list.get(i).setCompany_id(list.get(i).getNew_companyId());
					n=n+1;
				}
				if(!"".equals(list.get(i).getNew_enterprise_id())&&!list.get(i).getEnterprise_id().equals(list.get(i).getNew_enterprise_id())){
					list.get(i).setEnterprise_id(list.get(i).getNew_enterprise_id());
					n=n+1;
				}
				if("1".equals(list.get(i).getPromotion_show()) || n>0){
					upList1.add(list.get(i));
					n=0;
				}
			}
			dao.updateAllShowYnByMemberId(member_id);
			if(upList1.size()>0){
				dao.updateShowYn(upList1);
			}
			
			List<MemberCartVO> cartList = dao.getCartList(member_id,lang);
			//和库存对比数据
					for(int j=0;j<cartList.size();j++){
						MemberCartVO  cartVO =null;
						MemberCartVO  uP_cartVO =new  MemberCartVO();
						cartVO=cartList.get(j);
						
						cartVO.setState("0");
						uP_cartVO.setState("0");
						n=n+1;
						
						//售罄
						if(!"".equals(cartVO.getMaximum_n()) && ("0").equals(cartVO.getMaximum_n())){
							cartVO.setState("1");
							uP_cartVO.setState("1");
							n=n+1;
						} 
						//规格说明
						if(!"".equals(cartVO.getStandard_title_n()) && !cartVO.getStandard_title_n().trim().equals(cartVO.getStandard_title().trim())){
							cartVO.setStandard_title(cartVO.getStandard_title_n());
							uP_cartVO.setStandard_title(cartVO.getStandard_title_n());
							n=n+1;
						}
						//单价
						if(!"".equals(cartVO.getGood_price_n()) && !cartVO.getGood_price_n().equals(cartVO.getGood_price())){
							cartVO.setGood_price(cartVO.getGood_price_n());
							uP_cartVO.setGood_price(cartVO.getGood_price_n());
							n=n+1;
						}
						//图片
						if(!"".equals(cartVO.getGood_img_n())&& !cartVO.getGood_img_n().equals(cartVO.getGood_img())){
							cartVO.setGood_img(cartVO.getGood_img_n());
							uP_cartVO.setGood_img(cartVO.getGood_img_n());
							n=n+1;
						}
						//商品名
						if(!"".equals(cartVO.getGood_name())&& !cartVO.getGood_name_n().equals(cartVO.getGood_name())){
							cartVO.setGood_name(cartVO.getGood_name_n());
							uP_cartVO.setGood_name(cartVO.getGood_name_n());
							n=n+1;
						}
						//规格库存
						if(!"".equals(cartVO.getMaximum_n()) && !cartVO.getMaximum_n().equals(cartVO.getMaximum())){
							cartVO.setMaximum(cartVO.getMaximum_n());
							uP_cartVO.setMaximum(cartVO.getMaximum_n());
							n=n+1;
						}
						//库存不足
						if(!"".equals(cartVO.getMaximum_n())&&(Integer.parseInt(cartVO.getMaximum())>0)&&(Integer.parseInt(cartVO.getMaximum())<Integer.parseInt(cartVO.getNum()))){
							cartVO.setState("4");
							uP_cartVO.setState("4");
							n=n+1;
							//下架
							if((!"".equals(cartVO.getGood_state()) && ("2").equals(cartVO.getGood_state())) || (!"".equals(cartVO.getGood_state()) && ("0").equals(cartVO.getGood_state()))){
								cartVO.setState("3");
								uP_cartVO.setState("3");
								n=n+1;
							}
						}
						//下架
						if((!"".equals(cartVO.getGood_state()) && ("2").equals(cartVO.getGood_state())) || (!"".equals(cartVO.getGood_state()) && ("0").equals(cartVO.getGood_state()))){
							cartVO.setState("3");
							uP_cartVO.setState("3");
							n=n+1;
						}
						//失效
						if("".equals(cartVO.getGood_state())){
							cartVO.setState("2");
							uP_cartVO.setState("2");
							n=n+1;
						}else{
							if("0".equals(cartVO.getState_failure())){
								cartVO.setState("2");
								uP_cartVO.setState("2");
								n=n+1;
							}
						}
						//判断不支持配送
						if(lang==null){
							if(!"".equals(cartVO.getSend_temp_id())){
								List<SendTempItemVO> sen_temp_list = goodService.getSendTempItemBySendTempId(cartVO.getSend_temp_id(),city_id3);
								
								if(sen_temp_list.size()==0){
									cartVO.setState("5");
									uP_cartVO.setState("5");
									n=n+1;
								}
								
							}
						}else{
							if(!"".equals(cartVO.getGood_temp_id())){
								GoodDeliveryInterCountryVO gooddeliveryintercountryvo = goodService.getSendTempItemBySendTempIdEn(cartVO.getGood_temp_id(),country_id);
								
								if(gooddeliveryintercountryvo==null){
									cartVO.setState("5");
									uP_cartVO.setState("5");
									n=n+1;
								}
								
							}
						}
						
						if(n>0){
							uP_cartVO.setCart_id(cartVO.getCart_id());
							upList2.add(uP_cartVO);
							n=0;
						}
					}
			if(upList2.size()>0){
				dao.updateMemberCartList(upList2);
			}
			//排序
			List<MemberCartVO> memberCartList = dao.selectNewMemberCartList(member_id,lang);
			//memberCartList.add(e)
			for(int i =0; i<memberCartList.size();i++){
				ArrayList<MemberCartVO> tempList = new ArrayList<MemberCartVO>();
				for(int j=0;j<memberCartList.get(i).getGood_Info().size();j++){
					for(int k=0;k<memberCartList.get(i).getGood_Info().get(j).getGood_list().size();k++){
						tempList.add(memberCartList.get(i).getGood_Info().get(j).getGood_list().get(k));
					}
				}
				memberCartList.get(i).setGood_list(tempList);
				memberCartList.get(i).setGood_Info(null);
				
				memberCartList.get(i).setCompany_name(memberCartList.get(i).getEnterprise_name());
				memberCartList.get(i).setEnterprise_name(null);
				memberCartList.get(i).setFailure_state("0");
				for(int k=0;k<memberCartList.get(i).getGood_list().size();k++){
					MemberCartVO  memberCartVO =null;
					memberCartVO=memberCartList.get(i).getGood_list().get(k);
					
					memberCartVO.setFailure_state("0");
					memberCartVO.setGood_name_n(null);
					memberCartVO.setStandard_title_n(null);
					memberCartVO.setGood_price_n(null);
					memberCartVO.setGood_img_n(null);
					memberCartVO.setMaximum_n(null);
					memberCartVO.setNew_companyId(null);
					memberCartVO.setState_failure(null);
					memberCartVO.setMember_level(null);
					memberCartVO.setMax_level(null);
				}
					
			}
			//失效状态处理
			List<MemberCartVO> invalidList =dao.getInvalidList(member_id,lang);
			if(invalidList.size()>0){
				for(int i=0;i<invalidList.size();i++){
					invalidList.get(i).setFailure_state("1");
				}
				MemberCartVO  invalid_vo =new  MemberCartVO();
				invalid_vo.setFailure_state("1");
				invalid_vo.setCompany_name("失效商品");
				invalid_vo.setGood_list(invalidList);
				memberCartList.add(invalid_vo);
			}
		return memberCartList;
	}

	@Override
	public List<PromotionVO> promtionListById(String member_id) {
		String contentStr="";
        DecimalFormat df = new DecimalFormat("#");  

		List<PromotionVO> list = promotiondao.promtionListById(member_id);
		for(int i=0;i<list.size();i++){
			
			List<PromotionItemVO> itemList=promotiondao.getPromotionItemList1(list.get(i).getPromotion_id());
			for(int j=0;j<itemList.size();j++){
				if("Y".equals(itemList.get(j).getPromotion_freight())){
					if("1".equals(itemList.get(j).getType())&&"0".equals(itemList.get(j).getReach_type())){
						String content="【满"+itemList.get(j).getReach()+"元减"+itemList.get(j).getReduce_cash()+"元包邮】  >";
						itemList.get(j).setContentStr(content);
						
					}
					if("1".equals(itemList.get(j).getType())&&"1".equals(itemList.get(j).getReach_type())){
						String content="【满"+itemList.get(j).getReach()+"件减"+itemList.get(j).getReduce_cash()+"元包邮】  >";
						itemList.get(j).setContentStr(content);
					}
				}else{
					if("1".equals(itemList.get(j).getType())&&"0".equals(itemList.get(j).getReach_type())){
						String content="【满"+itemList.get(j).getReach()+"元减"+itemList.get(j).getReduce_cash()+"元】  >";
						itemList.get(j).setContentStr(content);
						
					}
					if("1".equals(itemList.get(j).getType())&&"1".equals(itemList.get(j).getReach_type())){
						String content="【满"+itemList.get(j).getReach()+"件减"+itemList.get(j).getReduce_cash()+"元】  >";
						itemList.get(j).setContentStr(content);
					}
				}
			}
			list.get(i).setItemList(itemList);
			
			//微信端使用的参数
			String cartPromotionGoodsCash =promotiondao.getCartPromotionGoodsCash(list.get(i).getPromotion_id(),member_id);
			String count = promotiondao.getCartPromotionCount(list.get(i).getPromotion_id(),member_id);
			
			for(int j=0;j<itemList.size();j++){
				if("1".equals(itemList.get(j).getType())&&"0".equals(itemList.get(j).getReach_type())){
					double cash =Double.parseDouble(cartPromotionGoodsCash);
					Double obj1 = new Double(cash);  

					double reach =Double.parseDouble(itemList.get(j).getReach());
					Double obj2 = new Double(reach);  
					int retval =  obj1.compareTo(obj2); 
					
					if(retval>=0){
						if("Y".equals(itemList.get(j).getPromotion_freight())){
							if("1".equals(itemList.get(j).getCountry())){
								contentStr="已满足【满"+itemList.get(j).getReach()+"元减"+itemList.get(j).getReduce_cash()+"元包邮】  >";
							}else{
								contentStr="You've already saved US $"+itemList.get(j).getReduce_cash();
							}
						}else{
							if("1".equals(itemList.get(j).getCountry())){
								contentStr="已满足【满"+itemList.get(j).getReach()+"元减"+itemList.get(j).getReduce_cash()+"元】  >";
							}else{
								contentStr="You've already saved US $"+itemList.get(j).getReduce_cash();
							}
						}
						list.get(i).setStr(contentStr);
						list.get(i).setDeduct_money(itemList.get(j).getReduce_cash());
						
					}else if(retval < 0) {  
						if(j==0){
					    	BigDecimal b1 = new BigDecimal(cash);
					    	BigDecimal b2 = new BigDecimal(reach);
					    	Double need_cash= b2.subtract(b1).doubleValue();
					    	if("Y".equals(itemList.get(j).getPromotion_freight())){
					    		if("1".equals(itemList.get(j).getCountry())){
						    		contentStr="再购"+df.format(need_cash)+"元立享"+"【满"+itemList.get(j).getReach()+"元减"+itemList.get(j).getReduce_cash()+"元包邮】  >";
					    		}else{
					    			contentStr="Spend another US $"+df.format(need_cash)+" to get US $"+itemList.get(j).getReduce_cash()+" off.";
					    		}
					    	}else{
					    		if("1".equals(itemList.get(j).getCountry())){
						    		contentStr="再购"+df.format(need_cash)+"元立享"+"【满"+itemList.get(j).getReach()+"元减"+itemList.get(j).getReduce_cash()+"元】  >";
					    		}else{
					    			contentStr="Spend another US $"+df.format(need_cash)+" to get US $"+itemList.get(j).getReduce_cash()+" off.";
					    		}
					    	}
							list.get(i).setStr(contentStr);
							list.get(i).setDeduct_money(itemList.get(j).getReduce_cash());
							break;
						}
				    }
					
				}
				if("1".equals(itemList.get(j).getType())&&"1".equals(itemList.get(j).getReach_type())){
					if(Integer.parseInt(count)>=Integer.parseInt(itemList.get(j).getReach())){
						if("Y".equals(itemList.get(j).getPromotion_freight())){
							if("1".equals(itemList.get(j).getCountry())){
								contentStr="已满足【满"+itemList.get(j).getReach()+"件减"+itemList.get(j).getReduce_cash()+"元包邮】  >";
							}else{
								contentStr="You've already saved US $"+itemList.get(j).getReduce_cash();
							}
						}else{
							if("1".equals(itemList.get(j).getCountry())){
								contentStr="已满足【满"+itemList.get(j).getReach()+"件减"+itemList.get(j).getReduce_cash()+"元】  >";
							}else{
								contentStr="You've already saved US $"+itemList.get(j).getReduce_cash();
							}
						}
						list.get(i).setStr(contentStr);
						list.get(i).setDeduct_money(itemList.get(j).getReduce_cash());
					}
					if(Integer.parseInt(count)<Integer.parseInt(itemList.get(j).getReach())){
						if(j==0){
							int n= Integer.parseInt(itemList.get(j).getReach())-Integer.parseInt(count);
							if("Y".equals(itemList.get(j).getPromotion_freight())){
								if("1".equals(itemList.get(j).getCountry())){
									contentStr="再购"+n+"件立享"+"【满"+itemList.get(j).getReach()+"件减"+itemList.get(j).getReduce_cash()+"元包邮】  >";
								}else{
									contentStr="Buy another "+n+" piece(s) to get $"+itemList.get(j).getReduce_cash()+" off.";
								}
							}else{
								if("1".equals(itemList.get(j).getCountry())){
									contentStr="再购"+n+"件立享"+"【满"+itemList.get(j).getReach()+"件减"+itemList.get(j).getReduce_cash()+"元】  >";

								}else{
									contentStr="Buy another "+n+" piece(s) to get $"+itemList.get(j).getReduce_cash()+" off.";

								}
							}
							list.get(i).setStr(contentStr);
							list.get(i).setDeduct_money(itemList.get(j).getReduce_cash());
							break;
						}
					}
				}
			}//微信端使用的参数end
		}
		return list;
	}

	public AddressVO getMemberCartAddress(String member_id,String address_id) {
		return dao.getMemberCartAddress(member_id,address_id);
	}

	public int checkCartsStandardNums(String cart_ids) {
		return dao.checkCartsStandardNums(cart_ids);
	}

	public Map cartToAccounts(String cart_ids, MemberVO member,AddressVO addressVO,int ticketTotal, String lang) {
		//会员比例
		double member_rate = orderVOMapper.getDepositRate(member.getId());
		//MEMBER_PRICE_TICKET
		String ticket_rule = ConfigDao.loadConfig("MEMBER_PRICE_TICKET");
		//MEMBER_PRICE_PERCENT
		String percent_rule = ConfigDao.loadConfig("MEMBER_PRICE_PERCENT");
		//总售价
		double total_sell_price = 0;
		//购物车里兑换卷
		int use_ticket = 0;
		//兑换券抵的金额
		double reduce_money = 0;
		//买手优惠
		double buy_sale = 0;
		//活动优惠
		double act_sale = 0;
		//运费
		double total_freight  = 0;
		double freight =0;
		//所有商品是否都是纯现金
		boolean all_buy_type  = true;
		//是否显示兑换券
		String ticket_show_yn = "";
		String id_card_img_state = "0";
		List<MemberCartVO> resultCartList = dao.getMembercartByIds(cart_ids,addressVO.getAddress_id());
		for (int i = 0; i < resultCartList.size(); i++) {
			String num = resultCartList.get(i).getNum();
			String sell_price = resultCartList.get(i).getSell_price();
			String ticket_price = resultCartList.get(i).getTicket_price();
			String ticket = resultCartList.get(i).getTicket();
			total_sell_price = total_sell_price + Double.parseDouble(sell_price)*Integer.parseInt(num);
			//现金
			if(!"61".equals(resultCartList.get(i).getBuy_type())){
				use_ticket = use_ticket + Integer.parseInt(ticket)*Integer.parseInt(num);
				reduce_money = reduce_money +NumberUtil.RoundDouble( Integer.parseInt(ticket)*Integer.parseInt(num)*member_rate,2);
				all_buy_type = false;
			}
			buy_sale = buy_sale + Integer.parseInt(num)*buySale(resultCartList.get(i).getSell_price(), resultCartList.get(i).getBuy_type(), resultCartList.get(i).getTicket(), resultCartList.get(i).getTicket_price(),member.getLevel(),ticket_rule,percent_rule,member_rate);
		}
		
		//购物车里所有供应商
		List<String> priseIdList = new ArrayList<String>();
		List<String> priseNameList = new ArrayList<String>();
		for (int i = 0; i < resultCartList.size(); i++) {
			if(!priseIdList.contains(resultCartList.get(i).getEnterprise_id())){
				priseIdList.add(resultCartList.get(i).getEnterprise_id());
				priseNameList.add("由 "+resultCartList.get(i).getEnterprise_name()+" 发货");
			}	
		}
		//数据结构  (供应商-商品)    
		List<EnterpriseVO> enterPriseList  = new ArrayList<EnterpriseVO>(); 
		for (int i = 0; i < priseIdList.size(); i++) {
			EnterpriseVO enterPriseVO = new EnterpriseVO();
			List<MemberCartVO> memberCartList = new ArrayList<MemberCartVO>(); 
			enterPriseVO.setEnterprise_id(priseIdList.get(i));
			enterPriseVO.setEnterprise_name(priseNameList.get(i));
			for (int j = 0; j < resultCartList.size(); j++) {
				MemberCartVO memberCart = resultCartList.get(j);
				if(memberCart.getEnterprise_id().equals(priseIdList.get(i))){
					memberCartList.add(memberCart);
				}
			}
			enterPriseVO.setCartList(memberCartList);
			enterPriseList.add(enterPriseVO);
		}
		//接下来就要算折扣了(还有算运费)
		for (int i = 0; i < enterPriseList.size(); i++) {
			EnterpriseVO enterPriseVO = enterPriseList.get(i);
			enterPriseVO = calculateCartSales(enterPriseVO,member.getLevel());
			act_sale = act_sale + Double.parseDouble(enterPriseVO.getAct_sale());
			if(lang==null){
				freight = getFreightByEnterprise(enterPriseVO,addressVO.getAddress_id(),lang);
			}else{
				freight = getFreightByEnterpriseInter(enterPriseVO,addressVO.getAddress_id(),lang);
			}
			
			total_freight = total_freight+freight;
		}
		
		if("127".equals(member.getLevel()) ||"126".equals(member.getLevel())||all_buy_type){
			ticket_show_yn = "0";
		}else{
			ticket_show_yn = "1";
		}
		if(member.getIdcard_front_img()!=null && member.getIdcard_back_img()!=null){
			id_card_img_state = "1";
		}
		String level_ord=memberLevelItemDao.getMyLevleOrd(member.getId());
		String level_discount="";
		if("3".equals(level_ord)||"4".equals(level_ord)||"5".equals(level_ord)||"6".equals(level_ord)||"7".equals(level_ord)){
			level_discount= dicDao.getNameById(member.getLevel());
			level_discount=level_discount.replace("会员","优惠");
		}
		if ("8".equals(level_ord)||"9".equals(level_ord)||"10".equals(level_ord)) {
			try {
				level_discount= dicDao.getNameById(PropertieUtil.loadPropertie("expert_level"));
			} catch (Exception e) {
				e.printStackTrace();
			}
			level_discount=level_discount.replace("会员","优惠");
		}
		Map map = new HashMap();
		
		map.put("address", addressVO);
		map.put("use_ticket", use_ticket);
		map.put("reduce_money", reduce_money);
		map.put("total_ticket", ticketTotal);
		map.put("total_sell_price", total_sell_price);
		map.put("total_freight", total_freight);
		map.put("buy_sale", buy_sale);
		map.put("act_sale", act_sale);
		map.put("total_price", total_sell_price-act_sale-buy_sale);
		map.put("ticket_price", total_sell_price-act_sale-buy_sale-reduce_money);
		map.put("ticket_show_yn", ticket_show_yn);
		map.put("good_data", enterPriseList);
		map.put("card_img_state", id_card_img_state);
		map.put("level_discount", level_discount);
		
		return map;
	}
	
	public Map buyNowToAccounts(String standard_id, String num, MemberVO member, AddressVO addressVO,int ticketTotal, String lang) {
		//会员比例
		double member_rate = orderVOMapper.getDepositRate(member.getId());
		//MEMBER_PRICE_TICKET
		String ticket_rule = ConfigDao.loadConfig("MEMBER_PRICE_TICKET");
		//MEMBER_PRICE_PERCENT
		String percent_rule = ConfigDao.loadConfig("MEMBER_PRICE_PERCENT");
		//总售价
		double total_sell_price = 0;
		//购物车里兑换卷
		int use_ticket = 0;
		//兑换券抵的金额
		double reduce_money = 0;
		//买手优惠
		double buy_sale = 0;
		//活动优惠
		double act_sale = 0;
		//运费
		double total_freight  = 0;
		double freight =0;
		//所有商品是否都是纯现金
		boolean all_buy_type  = true;
		//是否显示兑换券
		String ticket_show_yn = "";
		//不使用卷总价
		double total_price = 0;
		//使用兑换券后价
		double ticket_price = 0;
		String id_card_img_state = "0";

		List<MemberCartVO> cartList = new ArrayList<MemberCartVO>();
		MemberCartVO memberCart = dao.getCartStandardById(standard_id,addressVO.getAddress_id());
		memberCart.setNum(num);
		total_sell_price = Double.parseDouble(memberCart.getSell_price())*Integer.parseInt(num);
		use_ticket = Integer.parseInt(memberCart.getTicket())*Integer.parseInt(num);
		buy_sale = Integer.parseInt(num)*buySale(memberCart.getSell_price(), memberCart.getBuy_type(), memberCart.getTicket(), memberCart.getTicket_price(),member.getLevel(),ticket_rule,percent_rule,member_rate);
		if(!"61".equals(memberCart.getBuy_type())){
			reduce_money = reduce_money + NumberUtil.RoundDouble(Integer.parseInt(memberCart.getTicket())*Integer.parseInt(num)*member_rate, 2);
			all_buy_type =false;
		}
		EnterpriseVO enterPriseVO = new EnterpriseVO();
		enterPriseVO.setEnterprise_id(memberCart.getEnterprise_id());
		if(lang==null){
			enterPriseVO.setEnterprise_name("由 "+memberCart.getEnterprise_name()+" 发货");
		}else{
			enterPriseVO.setEnterprise_name("Seller:"+memberCart.getEnterprise_name());
		}
		cartList.add(memberCart);
		enterPriseVO.setCartList(cartList);
		enterPriseVO = calculateCartSales(enterPriseVO,member.getLevel());
		act_sale = act_sale + Double.parseDouble(enterPriseVO.getAct_sale());
		
		if(lang==null){
			//国内运费
			 freight = getFreightByEnterprise(enterPriseVO,addressVO.getAddress_id(),lang);
		}else{
			//国际运费
			 freight = getFreightByEnterpriseInter(enterPriseVO,addressVO.getAddress_id(),lang);
		}
		
		total_freight = total_freight+freight;
		

		if("127".equals(member.getLevel()) ||"126".equals(member.getLevel())||all_buy_type){
			ticket_show_yn = "0";
		}else{
			ticket_show_yn = "1";
		}
		
		List<EnterpriseVO> enterList = new ArrayList<EnterpriseVO>();
		enterList.add(enterPriseVO);
		
		if(member.getIdcard_front_img()!=null && member.getIdcard_back_img()!=null){
			id_card_img_state = "1";
		}
		String level_ord=memberLevelItemDao.getMyLevleOrd(member.getId());
		String level_discount="";
		if("3".equals(level_ord)||"4".equals(level_ord)||"5".equals(level_ord)||"6".equals(level_ord)||"7".equals(level_ord)){
			level_discount= dicDao.getNameById(member.getLevel());
			level_discount=level_discount.replace("会员","优惠");
		}
		if ("8".equals(level_ord)||"9".equals(level_ord)||"10".equals(level_ord)) {
			try {
				level_discount= dicDao.getNameById(PropertieUtil.loadPropertie("expert_level"));
			} catch (Exception e) {
				e.printStackTrace();
			}
			level_discount=level_discount.replace("会员","优惠");
		}
		Map map = new HashMap();
		
		map.put("address", addressVO);
		map.put("use_ticket", use_ticket);
		map.put("reduce_money", reduce_money);
		map.put("total_ticket", ticketTotal);
		map.put("total_sell_price", total_sell_price);
		map.put("total_freight", total_freight);
		map.put("buy_sale", buy_sale);
		map.put("act_sale", act_sale);
		map.put("ticket_show_yn", ticket_show_yn);
		map.put("total_price", total_sell_price-act_sale-buy_sale);
		map.put("ticket_price", total_sell_price-act_sale-buy_sale-reduce_money);
		map.put("good_data", enterList);
		map.put("card_img_state", id_card_img_state);
		map.put("level_discount", level_discount);
		
		
		return map;
	}
	
	/**
	 * 计算购物车折扣
	 * @param enterPriseList
	 * @return
	 */
	private EnterpriseVO calculateCartSales(EnterpriseVO enterPrise,String member_level){
		List<PromotionGoodVO> actIds = new ArrayList<PromotionGoodVO>();
		List<String> typeOneAct = new ArrayList<String>();
		double act_sale = 0;
		List<MemberCartVO> cartList = enterPrise.getCartList();
		for (int i = 0; i < cartList.size(); i++) {
			actIds.addAll(cartList.get(i).getProGoodList());
		}
		for (int i = 0; i < actIds.size(); i++) {
			if("1".equals(actIds.get(i).getType())&&!typeOneAct.contains(actIds.get(i).getPromotion_id())){
				typeOneAct.add(actIds.get(i).getPromotion_id());
			}
		}
		
		if(actIds.size()==0){
			return enterPrise;
		}else{
			List<PromotionVO> proOneList = promotiondao.getAllPromotionByProGoodId(typeOneAct,member_level);
			for (int i = 0; i < proOneList.size(); i++) {
				PromotionVO promotion = proOneList.get(i);
				int reach_count = 0;
				double reach_money = 0;  
				if(proOneList.get(i).getItemList().size()>0){
					List<String> goodIdList = new ArrayList<String>();
					for (int j = 0; j < cartList.size(); j++) {
						boolean state = false;
						for (int k = 0; k < cartList.get(j).getProGoodList().size(); k++) {
							if("1".equals(cartList.get(j).getProGoodList().get(k).getType())&&cartList.get(j).getProGoodList().get(k).getPromotion_id().equals(promotion.getPromotion_id())){
								state = true;
								goodIdList.add(cartList.get(j).getGood_id());
							}
						}
						
						if(state){
							reach_count = reach_count + Integer.parseInt(cartList.get(j).getNum());
							reach_money = reach_money + Double.parseDouble(cartList.get(j).getSell_price())*Integer.parseInt(cartList.get(j).getNum());
						}
					}//End cartlist
					PromotionItemVO proItem = chooseCorrectSalesTypeOne(reach_count,reach_money,promotion);
					if(proItem.getId()!=null){
						double reduce_money = Double.parseDouble(proItem.getReduce_cash());
						act_sale = act_sale+reduce_money;
						for (int j = 0; j < cartList.size(); j++) {
							boolean state = false;
							if(goodIdList.contains(cartList.get(j).getGood_id())){
								state = true;
							}
							if(state){
								if("Y".equals(proItem.getPromotion_freight())){
									cartList.get(j).setFreight_state(true);	
								}
							}
						}
					}		
				}
			}
			enterPrise.setAct_sale(String.valueOf(act_sale));
			return enterPrise;
		}
	}
	
	private PromotionItemVO chooseCorrectSalesTypeOne(int reach_count,double reach_money,PromotionVO proGood){
		String reach_type = proGood.getItemList().get(0).getType();
		List<PromotionItemVO> proItemList = proGood.getItemList();
		PromotionItemVO proItem = new PromotionItemVO();
		if(proItemList==null||proItemList.size()==0){
			return proItem;
		}
		for (int i = 0; i < proItemList.size(); i++) {
			String reach = proItemList.get(i).getReach();
			//满钱
			if("0".equals(reach_type)){
				if(Double.parseDouble(reach)>reach_money){
					proItemList.remove(i);
					i--;
				}
			}
			//满件
			else if("1".equals(reach_type)){
				if(Integer.parseInt(reach)>reach_count){
					proItemList.remove(i);
					i--;
				}
			}
		}
		if(proItemList==null||proItemList.size()==0){
			return proItem;
		}
		double suit_money = 0;
		int suit_count = 0;
		String pro_item_id="";
		for (int i = 0; i < proItemList.size(); i++) {
			String reach = proItemList.get(i).getReach();
			//满钱
			if("0".equals(reach_type)){
				if(Double.parseDouble(reach)>suit_money){
					suit_money = Double.parseDouble(reach);
					pro_item_id = proItemList.get(i).getId();
				}
			}
			//满件
			else if("1".equals(reach_type)){
				if(Integer.parseInt(reach)>suit_count){
					suit_count = Integer.parseInt(reach);
					pro_item_id = proItemList.get(i).getId();
				}
			}
		}
		
		for (int i = 0; i < proItemList.size(); i++) {
			if(proItemList.get(i).getId().equals(pro_item_id)){
				proItem = proItemList.get(i);
			}
		}	
		
		return  proItem;
	}
	
	private double getFreightByEnterprise(EnterpriseVO enterPriseVO,String address_id, String lang){
		List<MemberCartVO> cartList = enterPriseVO.getCartList();
		double friehgt = 0;
		String standard_id= "";
		String standard_num = "";
		for (int i = 0; i < cartList.size(); i++) {
			if(!cartList.get(i).isFreight_state()){
				standard_id = standard_id + cartList.get(i).getGood_standard_id() + "," ;
				standard_num = standard_num +  cartList.get(i).getNum()+"," ;
			}
		}
		if("".equals(standard_id)){
			return 0;
		}else{
			standard_id = standard_id.substring(0,standard_id.length()-1);
			standard_num = standard_num.substring(0,standard_num.length()-1);
			if(standard_id!=null&&!"".equals(standard_id)&&standard_num!=null&&!"".equals(standard_num)){
				if(lang==null){
					friehgt = goodTempService.calculateFeight(standard_id.split(","), standard_num.split(","), address_id);
				}else{
					
					friehgt = goodTempService.calculateFeightEn(standard_id.split(","), standard_num.split(","), address_id);
				}
			}
			return friehgt;
		}
		
	}
	private double getFreightByEnterpriseInter(EnterpriseVO enterPriseVO,String address_id, String lang){
		List<MemberCartVO> cartList = enterPriseVO.getCartList();
		double friehgt = 0;
		double friehgt_total = 0;
		String standard_id= "";
		String standard_num = "";
		String city_id = "";
		String country_id = "";
		AddressVO addressVO = addressDao.getAddressByIdEn(address_id);
		city_id =addressVO.getCountry_id();
		if(addressVO.getProvince_id() != null){
			city_id = addressVO.getProvince_id();
		}
		if(addressVO.getCity_id() != null){
			city_id = addressVO.getCity_id();
		}
		country_id=addressVO.getCountry_id();
		for (int i = 0; i < cartList.size(); i++) {
				standard_id = standard_id + cartList.get(i).getGood_standard_id() + "," ;
				standard_num = standard_num +  cartList.get(i).getNum()+"," ;
				GoodVO goodVO = goodVOMapper.selectgood(cartList.get(i).getGood_id());
				if(goodVO.getGood_temp_id()!=null){
					GoodDeliveryInterCountryVO vo = goodService.getSendTempItemBySendTempIdEn(goodVO.getGood_temp_id(),country_id);
					if(vo !=null){
						if("1".equals(goodVO.getFreight_type())){	
							friehgt=goodTempService.getFreightByCityEn(standard_id.split(","), standard_num.split(","), city_id);
						}
					}
				}
				friehgt_total=friehgt_total+friehgt;
		}
		return friehgt_total;
		
	}
	
	/**
	 * 算会员优惠
	 */
	public double buySale(String sell_price, String buy_type, String ticket, String ticket_price,String member_level,String ticket_rule,String percent_rule,double rate){
		double buySale = 0;
		try {
			if(!PropertieUtil.loadPropertie("common_level").equals(member_level)){
				if(Integer.parseInt(ticket) >= Integer.parseInt(ticket_rule) || (Integer.parseInt(ticket)  / Double.parseDouble(sell_price))*100 >= Double.parseDouble(percent_rule)){
						if(!PropertieUtil.loadPropertie("buy_type_cash").equals(buy_type)){
							buySale  = Double.parseDouble(sell_price)-getMemberPrice(sell_price,buy_type,ticket,ticket_price,member_level,ticket_rule,percent_rule,rate);
						}
				}
			}
		}catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return NumberUtil.RoundDouble(buySale,2);
	}
	/**
	 * 算会员价
	 */
	public double getMemberPrice(String sell_price, String buy_type, String ticket, String ticket_price,String member_level,String ticket_rule,String percent_rule,double rate){
		double member_price = 0;
		
		try {
			if(!PropertieUtil.loadPropertie("common_level").equals(member_level)){
				//满足条件
				if(Integer.parseInt(ticket) >= Integer.parseInt(ticket_rule) || (Integer.parseInt(ticket)  / Double.parseDouble(sell_price))*100 >= Double.parseDouble(percent_rule)){
					
						if(PropertieUtil.loadPropertie("buy_type_cash").equals(buy_type)){
							member_price=0;
						}else if(PropertieUtil.loadPropertie("buy_type_ticket").equals(buy_type)){
							member_price = Integer.parseInt(ticket) *rate;
						}else if(PropertieUtil.loadPropertie("buy_type_cash_ticket").equals(buy_type)){
							member_price= Double.parseDouble(ticket_price) + (Integer.parseInt(ticket) * rate);
						}
				}
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		return NumberUtil.RoundDouble(member_price,2);
	}
	/**
	 * 获取购物车配送地址
	 */
	@Override
	public MemberVO getCartCityInfo(String member_id) {
		//获取缓存地址信息
		MemberVO vo=memberDao.getCartCity(member_id);
		MemberVO city_info=new MemberVO();
		MemberVO vo1=new MemberVO();
		AddressVO address = new AddressVO();
		String cart_address=null;
		String member_address="";
		String city_id=null;
		//先查默认地址
		address = memberDao.getMemberDefaultAddress(member_id);
		//查询最新一笔订单地址 或是普通地址
		if(address==null){
			address = memberDao.getMemberAddressByMemberId(member_id);
		}
		//未改动过缓存地址时
		if("N".equals(vo.getCart_default())){
			if(address !=null){//地址表不为空时
				city_id=memberDao.getCityId(address.getAddress_id());
				vo1=memberDao.getCityParentCity(city_id);
				city_info = packageAddress(vo1);
				member_address=memberDao.getMemberAddress(address.getAddress_id());
				city_info.setCart_address(member_address);
				city_info.setAddress_id(address.getAddress_id());
			}else{
				//判断缓存表信息
				city_info = checkeAddrese(vo,member_id);
			}
		}
		//在商品详情选择过其他配送区域
		if("Y".equals(vo.getCart_default())){
			//判断缓存表信息
			city_info = checkeAddrese(vo,member_id);
		}
		city_info.setPage_index(null);
		city_info.setPage_count(null);
		if(city_info.getCity_name2().equals(city_info.getCity_name1())){
			city_info.setCity_level("2");
		}else{
			city_info.setCity_level("3");
		}
		return city_info;
	}
	@Override
	public MemberVO getDefaultaAddress() {
		MemberVO default_info=new MemberVO();
		MemberVO vo=memberDao.getCityParentCity("1416");
		
		if("3".equals(vo.getCity_level())){
			default_info.setCity_name3(vo.getCart_name());
			default_info.setCity_id3(vo.getCart_city());
			vo=memberDao.getCityParentCity(vo.getCity_parent_id());
		}
		if("2".equals(vo.getCity_level())){
			default_info.setCity_id2(vo.getCart_city());
			default_info.setCity_name2(vo.getCart_name());
			vo=memberDao.getCityParentCity(vo.getCity_parent_id());
		}
		if("1".equals(vo.getCity_level())){
			default_info.setCity_id1(vo.getCart_city());
			default_info.setCity_name1(vo.getCart_name());
		}
		if(default_info.getCity_name2().equals(default_info.getCity_name1())){
			default_info.setCity_level("2");
		}else{
			default_info.setCity_level("3");
		}
		default_info.setCart_address("");
		default_info.setAddress_id("");
		
		return default_info;
	}
	@Override
	public MemberVO getDefaultaAddressInter(String city_id, String lang) {
		MemberVO default_info=new MemberVO();
		MemberVO vo=memberDao.getCityParentCityEn(city_id);
		
		/*if("3".equals(vo.getCity_level())){
			default_info.setCity_name3(vo.getCart_name());
			default_info.setCity_id3(vo.getCart_city());
			vo=memberDao.getCityParentCityEn(vo.getCity_parent_id());
		}*/
		if("2".equals(vo.getCity_level())){
			default_info.setCity_id2(vo.getCart_city());
			default_info.setCity_name2(vo.getCart_name());
			vo=memberDao.getCityParentCityEn(vo.getCity_parent_id());
		}else{
			default_info.setCity_id2("");
			default_info.setCity_name2("");
		}
		if("1".equals(vo.getCity_level())){
			default_info.setCity_id1(vo.getCart_city());
			default_info.setCity_name1(vo.getCart_name());
			vo=memberDao.getCityParentCityEn(vo.getCity_parent_id());
		}else{
			default_info.setCity_id1("");
			default_info.setCity_name1("");
		}
		if("0".equals(vo.getCity_level())){
			default_info.setCity_id0(vo.getCart_city());
			default_info.setCity_name0(vo.getCart_name());
		}
		default_info.setCart_address("");
		default_info.setAddress_id("");
		
		return default_info;
	}
	@Override
	public MemberVO packageAddress(MemberVO vo) {
		MemberVO address_info=new MemberVO();
		
		if("3".equals(vo.getCity_level())){
			address_info.setCity_name3(vo.getCart_name());
			address_info.setCity_id3(vo.getCart_city());
			vo=memberDao.getCityParentCity(vo.getCity_parent_id());
		}
		if("2".equals(vo.getCity_level())){
			address_info.setCity_name2(vo.getCart_name());
			address_info.setCity_id2(vo.getCart_city());
			vo=memberDao.getCityParentCity(vo.getCity_parent_id());
		}
		if("1".equals(vo.getCity_level())){
			address_info.setCity_id1(vo.getCart_city());
			address_info.setCity_name1(vo.getCart_name());
		}
		return address_info;
	}
	//验证缓存配送信息
	@Override
	public MemberVO checkeAddrese(MemberVO vo,String member_id) {
		String city_id=null;
		MemberVO city_info=new MemberVO();
		MemberVO vo1=new MemberVO();//guonei
		//缓存信息里的地址表id不为空时
		if(vo.getCart_address()!=null){
			//判断是否有效地址
			city_id=memberDao.getCityId(vo.getCart_address());
			if(city_id!=null){
				vo1=memberDao.getCityParentCity(city_id);
				city_info = packageAddress(vo1);
				String member_address=memberDao.getMemberAddress(vo.getCart_address());
				city_info.setAddress_id(vo.getCart_address());
				city_info.setCart_address(member_address);
			}else{
				//输入广州市天河区地址
				city_info = getDefaultaAddress();
				city_info.setAddress_id("");
				city_info.setCart_address("");
				memberDao.updataDeliveryAddress1(member_id);
			}
		}else{
			city_info = packageAddress(vo);
			city_info.setAddress_id("");
			city_info.setCart_address("");
		}
		return city_info;
	}

	public int getPackageCountByMemberId(String member_id) {
		return dao.getPackageCountByMemberId(member_id);
	}
	@Override
	public String selectCartGoodNum(String member_id, String lang) {
		return dao.selectCartGoodNum(member_id,lang);
	}
	@Override
	public int checkLimitedNums(Map<String,String> cart_ids) {
		return dao.checkLimitedNums(cart_ids);
	}
	@Override
	public String checkLimitedNumsByStandardId(String standard_id) {
		return dao.checkLimitedNumsByStandardId(standard_id);
	}
	@Override
	public MemberVO packageAddressEn(MemberVO vo) {
		MemberVO address_info=new MemberVO();
		
		/*if("3".equals(vo.getCity_level())){
			address_info.setCity_name3(vo.getCart_name());
			address_info.setCity_id3(vo.getCart_city());
			vo=memberDao.getCityParentCityEn(vo.getCity_parent_id());
			
		}*/
		if("2".equals(vo.getCity_level())){
			address_info.setCity_name2(vo.getCart_name());
			address_info.setCity_id2(vo.getCart_city_en());
			vo=memberDao.getCityParentCityEn(vo.getCity_parent_id());
		}else{
			address_info.setCity_name2("");
			address_info.setCity_id2("");
		}
		if("1".equals(vo.getCity_level())){
			address_info.setCity_id1(vo.getCart_city_en());
			address_info.setCity_name1(vo.getCart_name());
			vo=memberDao.getCityParentCityEn(vo.getCity_parent_id());
		}else{
			address_info.setCity_id1("");
			address_info.setCity_name1("");
		}
		if("0".equals(vo.getCity_level())){
			address_info.setCity_id0(vo.getCart_city_en());
			address_info.setCity_name0(vo.getCart_name());
		}
		return address_info;
	}
	@Override
	public MemberVO getCartCityInfoInter(String member_id, String lang) {
		//获取缓存地址信息
				MemberVO vo=memberDao.getCartCityEn(member_id);
				MemberVO city_info=new MemberVO();
				MemberVO vo1=new MemberVO();
				AddressVO address = new AddressVO();
				String cart_address=null;
				String member_address="";
				String city_id=null;
				String apt="";
				//先查默认地址
				address = memberDao.getMemberDefaultAddressEn(member_id);
				//查询最新一笔订单地址 或是普通地址
				if(address==null){
					address = memberDao.getMemberAddressByMemberIdEn(member_id);
				}
				//未改动过缓存地址时
				if("N".equals(vo.getCart_default_en())){
					if(address !=null){//地址表不为空时
						city_id=memberDao.getCityIdEn(address.getAddress_id());
						apt=addressVOMapper.getAddressEnApt(address.getAddress_id());
						vo1=memberDao.getCityParentCityEn(city_id);
						city_info = packageAddressEn(vo1);
						member_address=memberDao.getMemberAddressEn(address.getAddress_id());
						city_info.setCart_address(member_address);
						city_info.setAddress_id(address.getAddress_id());
						city_info.setApt(apt);
					}else{
						//判断缓存表信息
						city_info = checkeAddreseEn(vo,member_id,lang);
					}
				}
				//在商品详情选择过其他配送区域
				if("Y".equals(vo.getCart_default_en())){
					//判断缓存表信息
					city_info = checkeAddreseEn(vo,member_id,lang);
				}
				city_info.setPage_index(null);
				city_info.setPage_count(null);
				return city_info;
	}
	private MemberVO checkeAddreseEn(MemberVO vo, String member_id, String lang) {
		String city_id=null;
		String apt="";
		MemberVO city_info=new MemberVO();
		MemberVO vo1=new MemberVO();
		//缓存信息里的地址表id不为空时
		if(vo.getCart_address_en()!=null){
			//判断是否有效地址
			AddressVO addressVO =memberDao.getMemberAddressByIdEn(vo.getCart_address_en());
			if(addressVO!=null){
				city_id =addressVO.getCountry_id();
				if(addressVO.getProvince_id() != null){
					city_id = addressVO.getProvince_id();
				}
				if(addressVO.getCity_id() != null){
					city_id = addressVO.getCity_id();
				}
				apt = addressVOMapper.getAddressEnApt(vo.getCart_address_en());
				vo1=memberDao.getCityParentCityEn(city_id);
				city_info = packageAddressEn(vo1);
				city_info.setAddress_id(vo.getCart_address_en());
				city_info.setCart_address(addressVO.getAddress());
			}else{
				//输入各个国家的默认city_id
				city_info = getDefaultaAddressInter("51081", lang);
				city_info.setAddress_id("");
				city_info.setCart_address("");
				if(lang!=null){
					memberDao.updataDeliveryAddress1En(member_id,"51081");
				}
			}
		}else{
			city_info = packageAddressEn(vo);
			city_info.setAddress_id("");
			city_info.setCart_address("");
		}
		city_info.setApt(apt);
		return city_info;
	}

}
